<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
set_html('title','快递详情');
if($_RQ['op']=='main'){
	$id=intval($_RQ['id']);
	$sendtype = intval($_RQ['sendtype']);
	$order=pdo_get('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	$ordergoods=pdo_getall('jy_weishop_order_goods',array('orderid'=>$id,'uniacid'=>$_SESSION['uniacid']),array('goodsid','optionid','price','total','goodssn','productsn'));
	foreach($ordergoods as &$gv){
			$goodsinfo = pdo_get('jy_weishop_goods',array('id'=>$gv['goodsid'],'uniacid'=>$_SESSION['uniacid']),array('id','type','image','title','merchid'));
			$goodsinfo['total']=$gv['total'];
			$goodsinfo['price']=$gv['price'];
			//获取门店
			$stores = array();
			$goodsinfo['storeids'] = json_decode($goodsinfo['storeids'],true);
			if ($goodsinfo['isverify'] == 1) {
				if (empty($goodsinfo['storeids'])) {
					$stores = pdo_getall('jy_weishop_store',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'type'=>array(2,3)));
				}else {
					foreach($goodsinfo['storeids'] as $sv){
						$stores[]= pdo_get('jy_weishop_store',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'type'=>array(2,3),'id'=>$sv['id']));
					}
				}
			}elseif($shopset['openstore'] ==1){
				if (empty($goodsinfo['storeids'])) {
					$stores = pdo_getall('jy_weishop_store',array('uniacid'=>$_SESSION['uniacid'],'status'=>1));
				}else {
					foreach($goodsinfo['storeids'] as $sv){
						$stores[]= pdo_get('jy_weishop_store',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'id'=>$sv['id']));
					}
				}
			}
			$goodsinfo['store']=$stores;
			//商品规格
			if($gv['optionid']){
				$specs=pdo_getcolumn('jy_weishop_goods_option',array('id'=>$optionid),'specs');
				$specs=explode("_",$specs);
				foreach($specs as &$spec){
					$spec=pdo_getcolumn('jy_weishop_goods_spec_item',array('id'=>$spec),'title');
				}
				$goodsinfo['selespename']=implode("，",$specs);
			}
			$goodsinfo['buytypetitle']=$this->buytypes()[$order['buytype']];
			//获取商户
			$merchs =array();
			if($goodsinfo['merchid']){
				$merchinfo = pdo_get('jy_merch_user',array('id'=>$goodsinfo['merchid'],'uniacid'=>$_SESSION['uniacid']));
				$merchs[$goodsinfo['merchid']] = $merchinfo;
				$merchs[$goodsinfo['merchid']]['goods'][] = $goodsinfo;
			}else{
				$merchs[0]['goods'][] = $goodsinfo;
			}
			if($order['storeid']){
				$stores[]= pdo_get('jy_weishop_store',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'id'=>$order['storeid']));
			}
			$gv['goodsinfo']=$goodsinfo;
	}
	$bundlelist=$this->pdo_getall('order_express',array('orderid'=>$id));
	if($bundlelist){
		$express_types=$this->express_types;
		foreach($bundlelist as &$bl){
			$bl['express_name']=$express_types[$bl['express_id']]['name'];
			$bl['express']=$express_types[$bl['express_id']]['express'];
		}
	}
	$return['expresslist']=$this->model('model')->getExpressList($bundlelist[0]['express'],$bundlelist[0]['expresssn']);
	$return['bundlelist']=$bundlelist;
	$return['order']=$order;
	$return['ordergoods']=$ordergoods;
	exi($return);
}
//删除订单
if($_RQ['op']=='delete'){
	if(!$_RQ['id']){
		exi('订单不存在，请重新选择订单','error');
	}
	$this->model('order')->order_delete($_RQ['id'],true);
	exi('已删除订单!');
}
//恢复订单
if($_RQ['op']=='reset'){
	if(!$_RQ['id']){
		exi('订单不存在，请重新选择订单','error');
	}
	$this->model('order')->order_reset($_RQ['id'],true);
	exi('已恢复订单!');
}
//彻底删除订单
if($_RQ['op']=='rdelete'){
	if(!$_RQ['id']){
		exi('订单不存在，请重新选择订单','error');
	}
	$this->model('order')->order_rdelete($_RQ['id']);
	exi('已彻底删除订单!');
}
//取消订单
if($_RQ['op']=='cancel'){
	$id=intval($_RQ['id']);
	if($id){
		$this->model('order')->order_cancel($id);
		exi('删除成功！','','order.list/');		
	}else{		
		exi('删除失败！','error');
	}
}
//确认订单
if($_RQ['op']=='confirm'){
	if(!$_RQ['id']){
		exi('订单不存在，请重新选择订单','error');
	}
	$update=array('status'=>'3');
	pdo_update('jy_weishop_order',$update,array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	exi('已确认收货!');
}
//支付订单
if($_RQ['op']=='setpay'){
	$id = intval($_RQ['id']);
	if(!$id){
		exi('订单不存在，请重新选择订单','error');
	}
	$pay_id=pdo_getcolumn('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id),'pay_id');
	exi($pay_id);
}
?>